package com.carp.service.Impl;

import com.carp.entity.CarpFile;
import com.carp.mapper.CarpFileMapper;
import com.carp.service.CarpFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CarpFileServiceImpl implements CarpFileService {

    @Resource
    private CarpFileMapper carpFileMapper;

    //查询文件
    @Override
    public CarpFile selectByMd5(String md5) {
        //添加查询条件
        Map<String, Object> map = new HashMap<>();
        map.put("file_md5",md5);
        //查询
        List<CarpFile> carpFiles = carpFileMapper.selectByMap(map);

        if (carpFiles.isEmpty()){
            return null;
        }

        return carpFiles.get(0);
    }

    //添加一个文件
    @Override
    public Boolean insertFile(CarpFile carpFile) {

        int insert = carpFileMapper.insert(carpFile);

        return insert>=1;
    }
}
